<?php

class InventoryRentPage extends DatabaseTablePage
{
    const TABLE_TPL = "include/inventory_rent_table.tpl";
    const CLIENTS_VAR_NAME = "CLIENTS";
    const INVENTORY_ITEMS_VAR_NAME = "INVENTORY_ITEMS";

    public function Process()
    {
        parent::Process();
        $totalRevenue = InventoryRentManager::GetTotalRevenue();
        $this->SetVar("TOTAL_REVENUE", $totalRevenue);
    }

    protected function SetItemManager()
    {
        $this->itemManager = new InventoryRentManager();
    }

    protected function SetInventoryForm()
    {
        $this->form = new InventoryRentForm();
    }

    protected function GetTableTemplate()
    {
        return self::TABLE_TPL;
    }

    protected function GetInventoryTableHtml()
    {
        $items = $this->itemManager->SelectAll();
        $itemsCount = $this->itemManager->GetSelectCount();
        $this->SetVar("ITEMS_COUNT", $itemsCount);
        $clientsManager = new InventoryClientsManager();
        $clients = $clientsManager->SelectAll();
        $inventoryManager = new InventoryItemManager();
        $inventoryItems = $inventoryManager->SelectAll();
        return TemplateEngine::getView(
            $this->GetTableTemplate(),
            array(
                DatabaseTablePage::ITEMS_VAR_NAME => $items,
                self::INVENTORY_ITEMS_VAR_NAME => $inventoryItems,
                self::CLIENTS_VAR_NAME => $clients
            )
        );
    }
}